# -*- coding: utf-8 -*-

from flask.json import JSONEncoder as _JSONEncoder
from datetime import date, datetime
from decimal import Decimal
from exit import db
from flask.json import JSONEncoder as _JSONEncoder
from flask_apscheduler import APScheduler  # as _BaseAPScheduler
from apscheduler.schedulers.background import BackgroundScheduler

scheduler = APScheduler(BackgroundScheduler(timezone="Asia/Hong_Kong"))     # 一定要在一个没有循环引入的init文件中初始化


class JSONEncoder(_JSONEncoder):
    def default(self, o):
        import decimal
        if isinstance(o, decimal.Decimal):

            return float(o)

        super(JSONEncoder, self).default(o)


def img_path():     # 图片路径
    url = 'http://127.0.0.1:5000/'
    # url = 'http://39.105.141.79:5000/'
    return url


def coin_list_sort(num_list):
    # 1.找到第一大数字
    max_num = max(num_list)

    # 2.找到第二大数字
    tmp_set = set(num_list)
    tmp_set.remove(max_num)
    if not tmp_set:
        second_num = max(num_list)
    else:
        second_num = max(tmp_set)
    # print(second_num)

    # 3.把第一大数字变为第二大数字
    for i in range(len(num_list)):
        if num_list[i] == max_num:
            num_list[i] = second_num
    # 4.计算总和
    total = sum(num_list)
    return total


def team_reward_num(total):    # 团队奖励
    num = 0
    total = total // 10000
    if 1 <= total <= 10:
        num = total * 10
    elif 11 <= total <= 50:
        num = total * 20
    elif 51 <= total <= 100:
        num = total * 30
    elif 101 <= total <= 500:
        num = total * 40
    elif 501 <= total <= 1300:
        num = total * 50
    elif total > 1300:
        num = total * 0.05
    return num




